Ext.define('AM.view.ProcedureListView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.procedureListView',
		initComponent: function(){
		Ext.apply(this,{
		store : 'ProcedureJobStore',
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'),
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"     //"SINGLE"/"SIMPLE"/"MULTI"
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        store : 'ProcedureJobStore',
        displayInfo: true
        },{
        	dock: 'top',
	        xtype: 'toolbar',
		    items: [{
				       xtype :'button',
				       text: '考评评级',
				       icon: 'Ext/restful/images/cog_edit.png',
					   handler:editPingJi
			      	},'-',{
			      	   xtype :'button',
				       text: '考勤修改',
				       icon: 'Ext/restful/images/cog_edit.png',
					   handler:editWorkday
			      	},'-',' 查询日期: ', 
			      	{
			        xtype:'datefield',
			        format:'Y-m',                    
			        id: 'rate_search',            
			        width : 150
			      },'-',{
			      	     xtype : "combobox",
					     allowBlank:false,
					     labelAlign :"right",
						 fieldLabel: '选择科室',
						 id:"search1_department",
						 queryMode: 'local',
						 store :'TargetDepartStore',
						 displayField: 'name',
						 valueField: 'id',
						  listeners:{   
											afterrender:function(thiz){
						 	                                       if(Number(deptID)>0){
						 	                                       
						                                            thiz.setValue(Number(deptID));
						                                            thiz.setReadOnly(true);
						                                            
											}
											}
								}
						 
			      },'-', {
			            xtype: 'button',
			            text: '搜索',
			            icon : 'Ext/restful/images/find.png',
			            margin: '0 0 0 5',
			            handler: function () {
			                 var searchdate1 = Ext.getCmp('rate_search').getValue();
			                 var searchdepartment= Ext.getCmp('search1_department').getValue();
			                 if(searchdate1==null){
			                 	alert("请选择日期！")
			                 }else if(searchdepartment==null){
			                 		alert("请选择科室！")
			                 }else{
			                   var grid=this.ownerCt.ownerCt;
			                   Ext.Ajax.request({
										url : 'Rate_InserPingeji',
										success : function() {
											 grid.getStore().on('beforeload', function (store, options) {
			                                    var new_params = { serchdate:Ext.util.Format.date(searchdate1, 'Y-m'),searchdepartment:searchdepartment};
			                                 			   Ext.apply(store.proxy.extraParams, new_params);
			                                  				  });
			               						  grid.getStore().reload();
											},
										failure : function() {
														Ext.MessageBox.alert("提示", "查询失败！");
									    	},
									   params:{serchdate:Ext.util.Format.date(searchdate1, 'Y-m'),searchdepartment:searchdepartment}
									});	
			                 }
			                 
			                 
			               
//			                 grid.getStore().on('beforeload', function (store, options) {
//			                                    var new_params = { serchdate:Ext.util.Format.date(searchdate1, 'Y-m')};
//			                                    Ext.apply(store.proxy.extraParams, new_params);
//			                                    });
//			                 grid.getStore().reload();
//			                }
			        }
			   }]
	      
        }],
//        selType:  'cellmodel',
        plugins: [
			        Ext.create('Ext.grid.plugin.CellEditing', {
			            clicksToEdit: 1
			        })],
		columns: [
		            {text: '序号',  xtype: 'rownumberer',width:50,align:'center',tdCls:'background-color: #8EE5EE;'},
			        { width:0,align:'center',dataIndex: 'id', hidden:true },
			        { text: '科室',  dataIndex: 'department',  width:100,align:'center' },
			        { text: '人员',dataIndex: 'employee', width:100,align:'center' },
			        { text: '考评得分', dataIndex: 'grade', width:100,align:'center',editor: {
			                xtype: 'numberfield',
			                minValue: 0,
			                allowBlank: false,
			                maxValue:100
			        }
//			        renderer: function(value){
//								 if (value === 1.3) {
//										 return '<span >优秀</span>';
//								}
//								 if (value === 1.1) {
//										 return '<span >良好</span>';
//								}
//								 if (value === 1.0) {
//										 return '<span >合格</span>';
//								}
//								 if (value === 0.8) {
//										 return '<span >不合格</span>';
//								}
//						 },
//			        	field: {
//					        xtype: 'combobox',
//			                triggerAction: 'all',
//			                queryMode: 'local', 
//			                store:"PingJiStore",
//			                displayField:'name',
//			                valueField:'id'
//			              }
			        },
			        { text: '当月天数',  dataIndex: 'workday',  width:100,align:'center'},
			        { text: '出勤天数',  dataIndex: 'actualworkday',  width:100,align:'center',editor: {
			                xtype: 'numberfield',
			                minValue: 0,
			                allowBlank: false
			               // maxValue:this.ownerCt.ownerCt.getStore().getAt(0).get('workday')
//			                listeners: {
//                            'click': function (dataview, index, node, e) {
//                             var grid=this.ownerCt.ownerCt;
//                              var record = grid.getStore().getAt(0);
//                              alert(record.get('workday'));
//                        //do sth...  
//                    },
//                    scope: this
//                }
// 
			            }
			         },
			        { text: '日期',  dataIndex: 'date',  width:100,align:'center'},
			       
			        { text: '操作', dataIndex: 'id',width:80,align:'center',renderer : function(data, cell, record, rowIndex,columnIndex){
			        	    var resultStr = "<div class='controlBtn'>" +                              
                            "<a href='javascript:void("+record.get('id')+");' class='alarm_detail' onclick='listProcedureJobdetail("+record.get('id')+")'>查看详情</a>&nbsp;&nbsp;&nbsp;&nbsp;" +  
                            "</div>";     
         					 return resultStr;  
			       		  }
         	    	}

			     ],
			   listeners: {    
                 render: function(grid) {    
                         grid.on("itemmouseenter", function(view,record,mode,index,e) {  
                         grid.tip = Ext.create('Ext.tip.ToolTip', { 
                         	title: '考评维度',
                         	width: 420,
                         	height: 250,
                            target: view.el,            
//                          delegate: view.itemSelector, //选择行显示
                            delegate: view.cellSelector, //选择cell显示
                            trackMouse: true, 
                            listeners: {              
                                beforeshow: function updateTipBody(tip) {  
                                		gridColums = view.getGridColumns();
  									 	column = gridColums[tip.triggerElement.cellIndex];
  									 	if(column.dataIndex === 'grade'){
  									 	myToolTipText = '<div>（一）任务维度：任务维度的考评主要针对被考核人员所取得的<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;工作成果，考核职工本职工作 <div/>' +
			                            						  
						                            	 '<div>（二）态度维度：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
								                            	 '1.工作态度&nbsp;&nbsp;&nbsp; '+
								                            	 '2.劳动纪律&nbsp;&nbsp;&nbsp;'+
								                            	 '3.品质素养'+
								                          '<div/>'+
						                            	 '<div>（三）管理维度：指科室负责人及科室副主任，为完成工作所应<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;具备的协作精神、管理技能、工作作风等 <div/>' +
						                            	 '<div>（四）周边维度：考核工作（业务）相关科室的团队合作精神，<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;促进工作流程在科室间的顺利推进<div/>' +		                          
						                            	  '<div>（五）能力维度：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
						                            	  		 '1.人际交往能力&nbsp;&nbsp;&nbsp;'+
						                            	  		 '2.影响力&nbsp;&nbsp;&nbsp;'+
						                            	  		 '3.领导能力&nbsp;&nbsp;&nbsp;'+
						                            	  		 '4.沟通能力<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
						                            	  		 '5.判断和决策能力&nbsp;&nbsp;&nbsp;'+
						                            	  		 '6.计划和执行能力&nbsp;&nbsp;&nbsp;'+
						                            	  		 '7.知识学习能力'+
						                            	  '<div/>'
			                            	  tip.update(myToolTipText);
			  								 
  									 	}else {
										    return false;
										   }
                                }  
                            }  
                        });  
      
                     });    
                 }    
             } 
             						});
			   this.callParent(arguments);
  	}
					
})	   
				    					
function editPingJi(){
		var grid=this.ownerCt.ownerCt;
		var selections = grid.getSelectionModel().getSelection();
			if(selections){
					if(selections.length==0){
							Ext.MessageBox.alert("提示","请检查是否选中所有行！");
							}else{   
									var grades=[]; var ids=[];
									for(var i=0;i<selections.length;i++){
										var record = selections[i];
										grades.push(record.get("grade"));
										ids.push(record.get("id"))
									  }
										Ext.Ajax.request({
										url : 'Rate_pingji',
										success : function() {
//										 Ext.getCmp('performanceGridView').getStore().on('beforeload', function (store, options) {
//                                     	  var new_params = {searchValue:Ext.util.Format.date(searchValue, 'Y-m')}
//                                    	  Ext.apply(store.proxy.extraParams, new_params);
//                                  	   });
									 		 grid.getStore().reload();	
									 		 grid.getSelectionModel().deselectAll();
										},
											failure : function() {
												Ext.MessageBox.alert("提示", "保存失败！");
											},
											params : {
												    ids:ids,
												    grades:grades
												}
									});	
							}
					}	
}
function editWorkday(){
		var grid=this.ownerCt.ownerCt;
		var selections = grid.getSelectionModel().getSelection();
			if(selections){
					if(selections.length==0){
							Ext.MessageBox.alert("提示","请检查是否选中所有行！");
							}else{   
									var workdays=[]; var ids=[];
									for(var i=0;i<selections.length;i++){
										var record = selections[i];
										workdays.push(record.get("actualworkday"));
										ids.push(record.get("id"))
									  }
										Ext.Ajax.request({
										url : 'Rate_editWorkDay',
										success : function() {
									 		 grid.getStore().reload();	
									 		 grid.getSelectionModel().deselectAll();
										},
											failure : function() {
												Ext.MessageBox.alert("提示", "保存失败！");
											},
											params : {
												    ids:ids,
												    workdays:workdays
												}
									});	
							}
					}	
}

function listProcedureJobdetail(id){
							    RateID=id;
								Ext.Ajax.request({
										url : 'jobDetail_ListProcedureJobDetail',
										success : function() {
											
									//
										Ext.getCmp('myProceduregrid').getStore().on('beforeload', function (store, options) {
                                     	  var new_params = {RateID:RateID};
                                    	  Ext.apply(store.proxy.extraParams, new_params);
                                  	   });
										 Ext.getCmp('myProceduregrid').getStore().reload();
											  win.show();
										},
										failure : function() {
											Ext.MessageBox.alert("提示", "查询失败！");
										},
										params : {
											RateID:RateID
										}
									});		
									

	 var mygrid=Ext.create('Ext.grid.Panel', {
				    id:'myProceduregrid',
				    width : 800,
				    columnLines:true,
				    store:'ProcedureJobDetailStore',
				    plugins: [{
			            ptype: 'rowexpander',
			            rowBodyTpl : new Ext.XTemplate(
			                '<p><b>工作要求:</b> {jobRequirement}</p>'
			                
			            )
			        }],
				    columns: [
				    { text: '序号', width:50,align:'center',xtype: 'rownumberer'},
			        { text: '名称', dataIndex: 'name', width:160,align:'center'},
			        { text: '科室',  dataIndex: 'department.name',  width:180,align:'center' },
			        { text: '人员',dataIndex: 'employee.name', width:100,align:'center' },
			        { text: '状态',  dataIndex:'state',  width:80,align:'center',renderer: function(value){
								 if (value === 1) {
										 return '未办理';
								 }if (value ===2) {
										 return '办理中';
								 }if (value === 3) {
										 return '结束';
								 }	
			       		 }
			        },
			        { text: '工作要求',dataIndex: 'jobRequirement', width:80,align:'center' },
			        { text: '日期',  dataIndex: 'startdate',  width:100,align:'center',xtype: 'datecolumn',   format:'Y-m-d'  }
				     ]
				});
	 	
	 	var win = new Ext.Window({
				title : "项目详情",
				width : 800,
				height : 350,
				frame:true,
				layout:"fit",
			    minimizable:true,
	    	    maximizable:true,
				items :[mygrid],
				buttons : [{
							text : "确定",
							handler : function() {
								win.close();
							}
						},{
							text : "关闭",
							handler : function() {
							win.close();
											
							}
						}]
			});
							
 }
	 	
